package com.zjjk.transfer.source.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.zjjk.transfer.source.entity.SourceOrder;
import com.zjjk.transfer.source.mapper.SourceOrderMapper;
import com.zjjk.transfer.source.service.SourceOrderService;
import com.zjjk.transfer.source.param.SourceOrderPageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.core.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 订单信息 服务实现类
 *
 * @author xuziyang
 * @since 2021-03-26
 */
@Slf4j
@Service
@DS("source")
public class SourceOrderServiceImpl extends BaseServiceImpl<SourceOrderMapper, SourceOrder> implements SourceOrderService {

    @Autowired
    private SourceOrderMapper sourceOrderMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveSourceOrder(SourceOrder sourceOrder) throws Exception {
        return super.save(sourceOrder);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateSourceOrder(SourceOrder sourceOrder) throws Exception {
        return super.updateById(sourceOrder);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteSourceOrder(Long id) throws Exception {
        return super.removeById(id);
    }

    @Override
    public Paging<SourceOrder> getSourceOrderPageList(SourceOrderPageParam sourceOrderPageParam) throws Exception {
        Page<SourceOrder> page = new PageInfo<>(sourceOrderPageParam, OrderItem.desc(getLambdaColumn(SourceOrder::getCreateTime)));
        LambdaQueryWrapper<SourceOrder> wrapper = new LambdaQueryWrapper<>();
        IPage<SourceOrder> iPage = sourceOrderMapper.selectPage(page, wrapper);
        return new Paging<SourceOrder>(iPage);
    }

}
